Ext.onReady(function(){
	Ext.BLANK_IMAGE_URL = 'resources/images/s.gif';
	Ext.chart.Chart.CHART_URL = 'resources/charts.swf';
	
	Ext.namespace('hf.widget');
	Ext.namespace('hf.widget.column');
	Ext.namespace('hf.data');	
	
	Ext.QuickTips.init();
	defineViewPort();
	
	//define viewport
	function defineViewPort(){
		defineFormTextField;
		defineFormButton();
		defineHeaderToolbar(); //define header
		defineWidgets(); //define common widgets
		
		var config = {
			xtype: 'viewport',
			layout: 'anchor',
			loadMask: true,
			renderTo: 'viewport_container',
			items: [{
				title: labels['application.title'],
				xtype: 'tabpanel',
				anchor: '100% 100%',
				activeItem: 0,
				tbar: {xtype: 'header-toolbar'},
				items: [
					createGeneralTab(),
			        createRentTab(),
			        createElectricityTab(),
			        createWaterTab(),
			        createGasTab(),
			        createHeatingTab(),
			        createPhoneTab(),
			        createIntercomTab(),
			        createNetTab(),
			        createTvTab()
		       ]
			}]
		};
		Ext.create(config);
	};
	
	// Start a simple ping task that send reques to server
	var pingTask = {
			run: function(){
				Ext.Ajax.request({
					url: 'auth/ping.action',
					success: function(resp, opt){},
					failure: function(resp, opt){
						window.location = 'index.jsp';
					}
				});
    		},
    		interval: 10000 //10 seconds
	};
	Ext.TaskMgr.start(pingTask);
});